import re

from typing import List


class College:
    colleges = [
        (0, '未选择学院', ''),
        (1, '航空学院', '空'),
        (2, '航天学院', '天'),
        (3, '航海学院', '海'),
        (4, '材料学院', '材料'),
        (5, '机电学院', '机电'),
        (6, '力学与土木建筑学院', '土'),
        (7, '动力与能源学院', '能'),
        (8, '电子信息学院', '电子信息'),
        (9, '自动化学院', '自动化'),
        (10, '计算机学院', '计算机'),
        (11, '数学与统计学院', '数'),
        (12, '物理科学与技术学院', '物理'),
        (13, '化学与化工学院', '化工'),
        (14, '管理学院', '管理'),
        (15, '公共政策与管理学院', '公共'),
        (16, '软件学院', '软件'),
        (17, '生命学院', '生命'),
        (18, '外国语学院', '外国语'),
        (19, '教育实验学院', '教育实验'),
        (20, '国际教育学院', '国际'),
        (21, '国家保密学院', '保密'),
        (22, '马克思主义学院', '马'),
        (23, '西北工业大学伦敦玛丽女王大学工程学院', '玛丽'),
        (24, '微电子学院', '微'),
        (25, '网络空间安全学院', '安全'),
        (26, '民航学院', '民'),
        (27, '生态环境学院', '生态'),
        (28, '体育部', '体育'),
        (29, '工程实践训练中心', '训'),
        (30, '艺术教育中心', '艺'),
        (31, '继续教育学院（网络教育学院）', '继续'),
        (32, '图书馆', '图书馆'),
        (33, '档案馆', '档案馆'),
        (34, '教学研究与教师发展中心（高等教育研究所）', '教师'),
        (35, '分析测试中心', '分析'),
        (36, '无人系统技术研究院', '无人系统技术研究院'),
        (37, '无人系统发展战略研究中心', '无人系统发展战略研究中心'),
        (38, '文化遗产研究院', '遗产'),
        (39, '柔性电子研究院', '柔性'),
        (40, '医学研究院', '医学'),
        (41, '光电与智能研究院', '光电'),
        (42, '北京研究院', '北京'),
        (43, '西北工业大学（上海）协同创新中心', '协同'),
        (44, '重庆科创中心', '重庆'),
        (45, '深圳研究院', '深圳'),
        (46, '青岛研究院', '青岛'),
        (47, '宁波研究院', '宁波'),
        (48, '长三角研究院', '长三角'),
        (49, '国家大学科技园', '科技'),
        (50, '资产公司', '资产'),
        (51, '三六五所', '三六五'),
        (52, '出版社', '出版社'),
        (53, '共青团西北工业大学委员会', '团'),
        (54, '共青团西北工业大学委员会志愿服务工作部', '志愿'),
        (55, '党委学生工作部', '党委'),
    ]

    @staticmethod
    def modify(college: str) -> str:
        if college is None:
            return College.colleges[0][1]
        res = []
        for c in College.colleges:
            if re.search(c[2], college) is not None:
                res.append(1)
            else:
                res.append(0)
        s = sum(res)
        if s == 1:
            return College.colleges[0][1]
        elif s == 2:
            for i in range(len(res)):
                if i == 0:
                    continue
                if res[i] == 1:
                    return College.colleges[i][1]
        else:
            for i in range(len(res)):
                if res[i] == 1:
                    if College.colleges[i][0] == 14:
                        return College.colleges[15][1]
                    if College.colleges[i][0] == 53:
                        return College.colleges[54][1]

    @staticmethod
    def int2str(i: int) -> str:
        if i < 0 or i > 55:
            return College.colleges[0][1]
        return College.colleges[i][1]

    @staticmethod
    def str2int(s: str) -> int:
        s = College.modify(s)
        for c in College.colleges:
            if c[1] == s:
                return c[0]
        return 0


class Sex:
    sex = [
        (0, '女'),
        (1, '男'),
        (2, "未知")
    ]

    @staticmethod
    def str2int(s: str) -> int:
        if s == '女':
            return 0
        if s == '男':
            return 1
        return 2

    @staticmethod
    def int2str(i: int) -> str:
        if i < 0 or i > 2:
            return Sex.sex[2][1]
        return Sex.sex[i][1]


class MainTrack:
    tracks = [
        (0, '未知', ['']),
        (1, '课外学术科技作品竞赛', ['科技', '学术']),
        (2, '创业计划作品竞赛', ['创业'])
    ]

    @staticmethod
    def modify(track: str) -> str:
        if track is None:
            return MainTrack.tracks[0][1]
        res = []
        for c in MainTrack.tracks:
            res_len = len(res)
            for pattern in c[2]:
                if re.search(pattern, track) is not None:
                    res.append(1)
                    break
            if res_len == len(res):
                res.append(0)
        s = sum(res)
        if s == 1:
            return MainTrack.tracks[0][1]
        else:
            for i in range(len(res)):
                if i == 0:
                    continue
                if res[i] == 1:
                    return MainTrack.tracks[i][1]

    @staticmethod
    def int2str(i: int) -> str:
        if i < 0 or i > 2:
            return MainTrack.tracks[0][1]
        return MainTrack.tracks[i][1]

    @staticmethod
    def str2int(s: str) -> int:
        s = MainTrack.modify(s)
        for c in MainTrack.tracks:
            if c[1] == s:
                return c[0]
        return 0

    @staticmethod
    def fromSubTrack(i: int) -> int:
        if i == 0:
            return 0
        elif 0 < i < 5:
            return 1
        elif i < 10:
            return 2
        return 0


class SubTrack1:
    tracks = [
        (0, '未知', ['']),
        (1, '科技发明制作A类', ['A', 'a']),
        (2, '科技发明制作B类', ['B', 'b']),
        (3, '自然科学学术论文', ['自然']),
        (4, '哲学社会科学类社会调查报告和学术论文', ['哲学']),
        (5, '科技创新与未来产业', ['创新', '未来']),
        (6, '社会治理和公共服务', ['治理', '公共']),
        (7, '生态环保和可持续发展', ['生态', '可持续', '发展']),
        (8, '乡村振兴和农业农村现代化', ['乡村', '振兴', '农村', '农业']),
        (9, '文化创意和区域合作', ['文化', '区域', '创意', '合作'])
    ]

    @staticmethod
    def modify(track: str) -> str:
        if track is None:
            return SubTrack1.tracks[0][1]
        res = []
        for c in SubTrack1.tracks:
            res_len = len(res)
            for pattern in c[2]:
                if re.search(pattern, track) is not None:
                    res.append(1)
                    break
            if res_len == len(res):
                res.append(0)
        s = sum(res)
        if s == 1:
            return SubTrack1.tracks[0][1]
        else:
            for i in range(len(res)):
                if i == 0:
                    continue
                if res[i] == 1:
                    return SubTrack1.tracks[i][1]

    @staticmethod
    def int2str(i: int) -> str:
        if i < 0 or i > 9:
            return SubTrack1.tracks[0][1]
        return SubTrack1.tracks[i][1]

    @staticmethod
    def str2int(s: str) -> int:
        s = SubTrack1.modify(s)
        for c in SubTrack1.tracks:
            if c[1] == s:
                return c[0]
        return 0


class SubTrack2:
    tracks = [
        (0, '未知', ['']),
        (1, '机械与控制', ['机械', '控制']),
        (2, '信息技术', ['信息']),
        (3, '数理', ['数']),
        (4, '生命科学', ['生命']),
        (5, '能源化工', ['能源', '化工'])
    ]

    @staticmethod
    def modify(track: str) -> str:
        if track is None:
            return SubTrack2.tracks[0][1]
        res = []
        for c in SubTrack2.tracks:
            res_len = len(res)
            for pattern in c[2]:
                if re.search(pattern, track) is not None:
                    res.append(1)
                    break
            if res_len == len(res):
                res.append(0)
        s = sum(res)
        if s == 1:
            return SubTrack2.tracks[0][1]
        else:
            for i in range(len(res)):
                if i == 0:
                    continue
                if res[i] == 1:
                    return SubTrack2.tracks[i][1]

    @staticmethod
    def int2str(i: int) -> str:
        if i < 0 or i > 5:
            return SubTrack2.tracks[0][1]
        return SubTrack2.tracks[i][1]

    @staticmethod
    def str2int(s: str) -> int:
        s = SubTrack2.modify(s)
        for c in SubTrack2.tracks:
            if c[1] == s:
                return c[0]
        return 0


def type2track(s: str) -> List[str]:
    m = MainTrack.str2int(s)
    s1 = SubTrack1.str2int(s)
    s2 = SubTrack2.str2int(s)
    if s1 != 0:
        m = MainTrack.fromSubTrack(s1)
    return [
        MainTrack.int2str(m),
        SubTrack1.int2str(s1),
        SubTrack2.int2str(s2),
    ]


def track2type(t: list) -> List[int]:
    if len(t) != 3:
        return [0, 0, 0]
    return [
        MainTrack.str2int(t[0]),
        SubTrack1.str2int(t[1]),
        SubTrack2.str2int(t[2])
    ]


if __name__ == '__main__':
    for c in SubTrack2.tracks:
        print('{value:"'+c[1]+'",label:"'+c[1]+'"},')
